package cn.kgc.mushroomdatabaseprovider.controller;

import cn.kgc.mushroomcommon.pojo.Address;
import cn.kgc.mushroomdatabaseprovider.service.AddressService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/database/provider/address")
public class AddressController {
    @Resource
    AddressService addressService;

    @RequestMapping("/query/address/view/list/by/uid")
    public List<Address> selectAddressListByView(@RequestParam(value = "uidaddress",defaultValue = "0") Integer uidaddress){
        return addressService.selectAddressListByView(uidaddress);
    }

    @RequestMapping("/insertaddress")
    public Map<String,Object> insertaddress(@RequestBody Address address){
        Map<String,Object> map = new HashMap<>();
         int insertaddress = addressService.insertaddress(address);
         if(insertaddress>0){
             map.put("status","添加成功");
         }else{
             map.put("status","添加失败");
         }
           return  map;
    }

    @RequestMapping("/deleteaddress")
    public Map<String,Object> deleteaddress(@RequestParam("id")Integer id){
        Map<String,Object> map = new HashMap<>();
        int deleteaddress = addressService.deleteaddress(id);
        if(deleteaddress>0){
            map.put("status","删除成功");
        }else{
            map.put("status","删除失败");
        }
        return  map;
    }

    @RequestMapping("/updateaddress")
    public Map<String,Object> updateaddress(@RequestParam("id")Integer id){
        Map<String,Object> map = new HashMap<>();
        int updateaddress = addressService.updateaddresss(id);
        if(updateaddress>0){
            map.put("status","修改成功");
        }else{
            map.put("status","修改失败");
        }
        return  map;
    }

    @RequestMapping("selectByStatus")
    public Address selectByStatus(@RequestParam("status")Integer status){
         Address address = addressService.selectByStatus(status);
         return address;
    }

    @RequestMapping("/updatemoren")
    public Map<String,Object> updatemoren(@RequestParam("id")Integer id){
        Map<String,Object> map = new HashMap<>();
        int updatemoren = addressService.updatemoren(id);
        if(updatemoren>0){
            map.put("status","修改成功");
        }else{
            map.put("status","修改失败");
        }
        return  map;
    }
}
